package com.shoppingmall.service.impl;

import com.shoppingmall.commons.Result;
import com.shoppingmall.mapper.UserMapper;
import com.shoppingmall.model.User;
import com.shoppingmall.model.UserInfo;
import com.shoppingmall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public void register(UserInfo userInfo) throws Exception {
        PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        String encode = passwordEncoder.encode(userInfo.getUser_password());
        userInfo.setUser_password(encode);
        userMapper.addUser(userInfo);
    }

    @Override
    public List<User> getUserList() {
        return userMapper.getUserList();
    }

    @Override
    public void updateStatus(int user_status, int user_id) {
        userMapper.updateStatus(user_status,user_id);
    }

    @Override
    public UserInfo getUser(int user_id) {
        return userMapper.getUser(user_id);
    }

    @Override
    public void updateUser(UserInfo userInfo) {

        userMapper.updateUser(userInfo);
    }


}
